using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;


namespace sCicero
{
    public class Subjects : Base
    {
        private const string SUBJECTS = "subjects";
        //private Data m_oData;

        public Subjects(ref Data oData)
        {
            m_oData = oData;
            m_Table = SUBJECTS;
        }

        public Errorcode New(string sName)
        {
            Hashtable oCols = new Hashtable();
            oCols.Add("name", sName);
            Errorcode oE = m_oData.New(ref m_oData, SUBJECTS,oCols);
            if (oE != Errorcode.NOERROR)
                m_LastError = m_oData.LastError();
            return oE;

            /*
            DataRow o_Dr = m_oData.GetGenericDataTable(SUBJECTS).NewRow();
            o_Dr["name"] = sName;
            m_oData.GetGenericDataTable(SUBJECTS).Rows.Add(o_Dr);
            m_oData.AcceptChanges(SUBJECTS);
            return Errorcode.NOERROR;
             * */
        }


        public DataRow[] Search(string sSubjectName)
        {
            return Search(sSubjectName, false);
        }

        //bEnforce, if true it must match
        public DataRow[] Search(string sSubjectName, bool bEnforce)
        {
            return m_oData.GetGenericDataTable(SUBJECTS).Select("name " + (bEnforce ? "=" : "like") + " '" + (bEnforce ? "" : "%") + sSubjectName + (bEnforce ? "":"%") +"'");
        }
    }
}
